﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using BooksOnline.Models.Entities;
using BooksOnline.Repositories;
using NUnit.Framework;

namespace BooksOnline.Tests
{
    /// <summary>
    /// Summary description for RecommendationRepositoryFixture
    /// </summary>
    [TestFixture]
    public class RecommendationRepositoryFixture : FixtureBase<Recommendation>
    {
        Recommendation _recommendation = new Recommendation();
        Book _book = new Book();
        Customer _customer = new Customer();
        RecommendationRepository recommendationRepository = new RecommendationRepository();

        [TestFixtureSetUp]
        protected override void SetUp()
        {
            _book.Author = new BookAuthor() { Id = Guid.NewGuid(), Name = "Author 1" };
            _book.Title = "Book 1";

            _customer.Id = Guid.NewGuid();
            _customer.Name = "Customer 1";

            _recommendation.Id = Guid.NewGuid();
            _recommendation.Text = "Recommended text";
            _recommendation.Book = _book;
            _recommendation.Customer = _customer;
            
            Session.Save(_book);
            Session.Save(_customer);
            Session.Save(_recommendation);
            Session.Flush();

            base.SetUp();
        }

        [Test]
        public void ById_works_well()
        {
            var actual = recommendationRepository.ById(_recommendation.Id);

            Assert.IsNotNull(actual);
            Assert.AreEqual(actual.Id, _recommendation.Id);
        }

        [Test]
        public void ByBookId_works_well()
        {
            var actual = recommendationRepository.ByBookId(_book.Id);

            Assert.IsNotNull(actual);
            Assert.IsTrue(actual.Count > 0);
            Assert.AreEqual(actual[0].Book.Id, _book.Id);
        }

        [Test]
        public void ByCustomerId_works_well()
        {
            var actual = recommendationRepository.ByCustomerId(_customer.Id);

            Assert.IsNotNull(actual);
            Assert.IsTrue(actual.Count > 0);
            Assert.AreEqual(actual[0].Customer.Id, _customer.Id);
        }
    }
}
